package com.zhongc.advance.common.code;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import com.zhongc.advance.common.Constant;
/**
 * 
 * 
 *                       
 * @Filename CheckCode.java
 *
 * @Description  验证码校验公共方法
 *
 * @Version 1.0
 *
 * @Author zhongc
 *
 * @Email zhong_ch@foxmail.com
 *       
 * @History 
 *<li>Author: zhongc</li>
 *<li>Date: 2015年7月14日</li>
 *<li>Version: 1.0</li>
 *<li>Content: create</li>
 *
 */
public class CheckCode {
	/**
	 * 验证码校验器
	 * @param session
	 * @param checkcode
	 * @return 返回map  boolean code(true or false)   message 
	 */
	public static Map<String,Object> checkCheckcode(HttpSession session, String checkcode){
			Map<String, Object> result = new HashMap<String, Object>();
			if(checkcode == null){
				result.put("code", false);
				result.put("message", "验证码不能为空");
				return result;
			}
			String code = (String)session.getAttribute(Constant.Session.SESSION_CHECKCODE_NAME);
			if(code == null){
				result.put("code", false);
				result.put("message", "验证码已过期,请刷新验证码");
				return result;
			}
			if(!code.equalsIgnoreCase(checkcode)){
				result.put("code", false);
				result.put("message", "验证码错误");
				return result;
			}
			result.put("code", true);
			return result;
		}
}

